<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body></body>
<script>

    const arr = [1, 2, 3]
    console.log('🚀 ~ This is a result of console.log ~ ✨: ', ...arr);
    const itera = arr[Symbol.iterator]()
    console.log('🚀 ~ This is a result of console.log ~ ✨: ', itera.next());

    // 声明字符串
    let str = '<a href="http://www.atguigu.com">尚硅谷</a>';
    const result = Object.fromEntries([
        ["name", "尚硅谷"],
        ["change", "黑马"],
    ]);
    console.log(result);
    let strb = [1, 2, 3, [3, 4], 5, 6];
    console.log(strb.flat());

    // class person {
    //     name;
    //     //设置私有属性
    //     age;
    //     weight;
    //     constructor(name, age, weight) {
    //         this.name = name;
    //         this.age = age;
    //         this.weight = weight;
    //     }
    // }
    // const p = new Person('张三', 12, '45kg')

    const d = new Promise((reslove, reject) => {
        setTimeout(() => {
            reslove('数据被读取')
        }, 1000)
    })
    const n = new Promise((reslove, reject) => {
        setTimeout(() => {
            reject('读取失败')
        }, 1000)
    })
    console.log(Promise.allSettled([d, n])); //多个promise传进去只会有成功的结果，但是他的方法里面有失败的结果
    console.log(Promise.all([d, n])); //如果有错，会返回错误的结果，不会返回成功的结果

    function main(config) {
        const dbhost = config ?.db ?.host
        console.log(dbhost)
    }
    main({
        db: {
            host: '192.0.0.7'
        }
    })

    //  实现一个 iterator
    const bog = {
        stu: [1, 4, 5],
        [Symbol.iterator]() {
            let index = 0;
            const _this = this
            return {
                next() {
                    if (index < _this.stu.length) {
                        return {
                            value: _this.stu[index],
                            done: false,
                        }
                    } else {
                        return {
                            value: undefined,
                            done: true
                        }
                    }
                }
            }
        }
    }
</script>

</html>
